clear
cd "~/Dropbox/Life cycle paper/JOP submission/Replication files/YPSP/"

clear
use "student data.dta"
set more off

*ADDITIONAL HOUSEKEEPING*

*recode dv to range between 0-1
*in model where dv is 1973 church attendance, church attendance is collapsed to 4-point rather than 5-point scale to match the 1965 church attendance scale which only has 4 points.
replace church473=church473/3
replace church82=church82/4
replace church97=church97/4

label define church_label 0 "0. never" 1 "1. every week"
label values church473 church82 church97 church_label

*binary partisanship measures
g ind65=1 if pid365==2
replace ind65=0 if pid365==1 | pid365==3
g rep65=1 if pid365==3
replace rep65=0 if pid365==1 | pid365==2

g ind73=1 if pid373==2
replace ind73=0 if pid373==1 | pid373==3
g rep73=1 if pid373==3
replace rep73 =0 if pid373==1 | pid373==2

tab relig65, gen(relig65_binary)

*********************************

*Table C5: Replicating main 1973-1982 results among non-southern respondents
local demo_controls ne73 south73 west73 male black colprep65 i.inc73 attend73 married73 children73 closewrents73 nam73
local background_controls i.relig65 i.church465 i.lit65 closewrents65 p_churchave65 mo_pid fa_pid p_educave65 p_incave65
local attitude_controls supportnam women marijuana econlib busing aid

xi: reg church82 rep73 ind73 i.church73 `demo_controls' `background_controls' `attitude_controls' , cl(psu)
quietly gen insample_full=e(sample)

eststo clear
xi: reg church82 rep73 ind73 i.church73 if insample_full==1 & south73!=1, cl(psu)
est store a1
xi: reg church82 rep73 ind73 i.church73 `demo_controls' if insample_full==1 & south73!=1, cl(psu)
est store a2
xi: reg church82 rep73 ind73 i.church73 `demo_controls' `background_controls' if insample_full==1 & south73!=1, cl(psu)
est store a3
xi: reg church82 rep73 ind73 i.church73 `demo_controls' `background_controls' `attitude_controls' if insample_full==1 & south73!=1, cl(psu)
est store a4
esttab a1 a2 a3 a4 using "church_1973_1982_nonsouth.tex", ///
keep(rep73 ind73 _Ichurch73_4  _Ichurch73_2 _Ichurch73_3 _Ichurch73_1 _cons) ///
star(* .10 ** 0.05) obslast nogaps ///
sfmt(4) se(2) b(2) replace booktabs compress label r2 ///
title("Republicans and Democrats diverged in church attendance between 1973 and 1982 (non-south)")  ///
nomtitles ///
coeflabels( ind73   "Independent" rep73 "Republican" _Ichurch73_1 "A few times a year" _Ichurch73_2 "Once or twice a month" _Ichurch73_3 "Almost every week" _Ichurch73_4 "Every week"  _cons "Intercept") ///
indicate( "demographic controls = *ne73*" "upbringing controls = *p_churchave65*" "attitudinal controls = *supportnam*") ///
nonotes



*Table C6: Restricted sample. Same PID in 1973 and 1982
drop insample_full
local demo_controls ne73 south73 west73 male black colprep65 inc73 attend73 children73 married73 closewrents73 nam73
local background_controls relig65_binary2 relig65_binary3 relig65_binary4 relig65_binary5 relig65_binary6 relig65_binary7 church465 lit65 closewrents65 p_churchave65 fa_pid65 mo_pid65 p_educave65 p_incave65
local attitude_controls supportnam marijuana women econlib busing aid

qui: xi: reg church82 rep73 ind73 i.church473 `demo_controls' `background_controls' `attitude_controls', cl(psu)
quietly gen insample_full=e(sample)

eststo clear
xi: reg church82 rep73 ind73 i.church73 if insample_full==1  & pid373==pid382, cl(psu)
est store a1
xi: reg church82 rep73 ind73 i.church73 `demo_controls' if insample_full==1  & pid373==pid382, cl(psu)
est store a2
xi: reg church82 rep73 ind73 i.church73 `demo_controls' `background_controls' if insample_full==1  & pid373==pid382, cl(psu)
est store a3
xi: reg church82 rep73 ind73 i.church73 `demo_controls' `background_controls' `attitude_controls' if insample_full==1  & pid373==pid382, cl(psu)
est store a4
esttab a1 a2 a3 a4 using "church_1973_1982_restricted_sample.tex", ///
keep(rep73 ind73 _Ichurch73_1 _Ichurch73_2  _Ichurch73_3 _Ichurch73_4 _cons) ///
star(* .10 ** 0.05) obslast nogaps ///
sfmt(4) se(2) b(2) replace booktabs compress label r2 ///
title("Republicans and Democrats diverged in church attendance between 1973 and 1982 (same PID)")  ///
nomtitles ///
coeflabels( ind73   "Independent" rep73 "Republican" _Ichurch73_1 "A few times a year" _Ichurch73_2 "Once or twice a month" _Ichurch73_3 "Almost every week" _Ichurch73_4 "Every week"  _cons "Intercept") ///
indicate( "demographic controls = *ne73*" "upbringing controls = *p_churchave65*" "attitudinal controls = *supportnam*") ///
nonotes


*Table C7: Restricted sample. 1973 PID as an instrument for 1982 PID
eststo clear
xi: ivregress 2sls church82 i.church73 (i.pid382=i.pid373) if insample_full==1 , first cl(psu)
est store a1
xi: ivregress 2sls  church82  i.church73 `demo_controls' (i.pid382=i.pid373) if insample_full==1  , first cl(psu)
est store a2
xi: ivregress 2sls  church82 i.church73 `demo_controls' `background_controls'  (i.pid382=i.pid373) if insample_full==1   , first cl(psu)
est store a3
xi: ivregress 2sls  church82  i.church73 `demo_controls' `background_controls' `attitude_controls'  (i.pid382=i.pid373)  if insample_full==1 , first cl(psu)
est store a4 
esttab a1 a2 a3 a4 using "church_1973_1982_ivregress.tex", ///
keep(   _Ipid382_2 _Ipid382_3 _Ichurch73_1 _Ichurch73_2  _Ichurch73_3 _Ichurch73_4 _cons) ///
star(* .10 ** 0.05) obslast nogaps ///
sfmt(4) se(2) b(2) replace booktabs compress label r2 ///
title("Republicans and Democrats diverged in church attendance between 1973 and 1982 (1973 partisanship as an instrument for 1982 partisanship)")  ///
nomtitles ///
coeflabels(    _Ipid382_2    "Independent"    _Ipid382_3 "Republican" _Ichurch73_1 "A few times a year" _Ichurch73_2 "Once or twice a month" _Ichurch73_3 "Almost every week" _Ichurch73_4 "Every week"  _cons "Intercept") ///
indicate( "demographic controls = *ne73*" "upbringing controls = *p_churchave65*" "attitudinal controls = *supportnam*") ///
nonotes
